<?php
namespace app\home\controller;

use app\common\access\MyAccess;
use app\common\access\MyLog;
use app\common\service\Action;
use think\Controller;
use think\Request;

class Index extends Controller
{

    public function _initialize()
    {
        $request = Request::instance();
        $root=$request->root();
        $action=$root.'/'.$request->module().'/'.$request->controller().'/'.$request->action();
        $this->assign("ROOT", $root);
        $this->assign("ACTION",$action);

        $this->assign("TITLE",config('site.title'));
        $this->assign("COPYRIGHT",config('site.copyright'));
        $log=new MyLog();
        config('log2db')&&$log->write('R');
    }

    public function index()
    {
        try {
            $request = Request::instance();
            if(session('S_LOGIN_TYPE')==2) {
                header('Location:' . $request->root().'/student/');
                exit();
            }

            MyAccess::getAccess();
            config('auth')&& MyAccess::checkAccess('R');
            $userinfo['username']=session('S_USER_NAME');//用户名登录名
            $userinfo['realname']=session('S_REAL_NAME');//真实姓名
            $userinfo['teacherno']=session('S_TEACHERNO');//真实姓名
            $userinfo['schoolname']=session('S_USER_SCHOOL_NAME');//学院名称
            $this->assign('USERINFO',$userinfo);
            $this->assign("TITLE",config('site.title'));
            $this->assign("COPYRIGHT",config('site.copyright'));
            $obj=new Action();
            $menuJson=array('menus'=>$obj->getUserAccessMenu(session('S_USER_NAME'),265));
            $this->assign('menu',json_encode($menuJson));
        } catch (\Exception $e) {
            MyAccess::throwException($e->getCode(), $e->getMessage());
        }
        return $this->fetch();
    }

    public function login()
    {
        $guid = getGUID(session_id());
        session('S_GUID', $guid);
        $page['guid']=$guid;
        $page['order']=rand(1,6);
        $page['many']=session('S_LOGINTIMES');
        $this->assign('page',$page);
        return $this->fetch();
    }

    public function login2()
    {
        $guid = getGUID(session_id());
        session('S_GUID', $guid);
        $page['guid']=$guid;
        $page['order']=rand(1,6);
        $page['many']=session('S_LOGINTIMES');
        $this->assign('page',$page);
        return $this->fetch();
    }

    public function  _empty(){
        return $this->fetch();
    }
}
